import { post, get } from '@/utils/request';
import { RolePermission} from '@/pages/backhub/common/role/store/types';

/**
 * 获取功能权限列表
 * @returns 功能权限列表
 */
export const getRolePermissionList = async (): Promise<RolePermission[]> => {
  return get(`/engine/starhub/rolePermission/getList`);
};

/**
 * 获取功能权限
 * @returns 功能权限信息
 */
export const getInfo = async (id: string): Promise<RolePermission[]> => {
  return get(`/engine/starhub/rolePermission/getInfo/${id}`);
};

/**
 * 创建功能权限
 * @param data 功能权限数据
 * @returns 创建的功能权限
 */
export const createRolePermission = async (data: Partial<RolePermission>): Promise<RolePermission> => {
  return post(`/engine/starhub/rolePermission/add`, data);
};

/**
 * 更新功能权限
 * @param id 功能权限ID
 * @param data 更新的数据
 * @returns 更新后的功能权限
 */
export const updateRolePermission = async (id: string, data: Partial<RolePermission>): Promise<RolePermission> => {
  data.id = id ;
  return post(`/engine/starhub/rolePermission/update`, data);
};

/**
 * 删除功能权限
 * @param id 功能权限ID
 */
export const deleteRolePermission = async (ids: string): Promise<void> => {
  return post(`/engine/starhub/rolePermission/deleteRecord`, { ids });
};


/**
 * 获取权限列表
 * @returns 权限列表
 */
export const getActivePermission = async (): Promise<any[]> => {
  return get(`/engine/starhub/permission/getActivePermission`);
};

